{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import defaultdict\n",
    "\n",
    "class Solution(object):\n",
    "    def numberOfBoomerangs(self, points):\n",
    "        \"\"\"\n",
    "        :type points: List[List[int]]\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        nums = 0\n",
    "        for x1, y1 in points:\n",
    "            distance = defaultdict(int)\n",
    "            for x2, y2 in points:\n",
    "                dx = abs(x2 - x1)\n",
    "                dy = abs(y2 - y1)\n",
    "                d = dx * dx + dy * dy\n",
    "                distance[d] += 1\n",
    "\n",
    "            nums += sum(n * (n-1) for n in distance.values())\n",
    "        return nums        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.numberOfBoomerangs([[0,0],[1,0],[2,0]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
